home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / r_hello.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  3KB  |  92 lines

  1. {$X+,V-,B-}
  2. program RecHello;
  3.  
  4. { Simple IPX demonstration program. Run this program on 1 workstation,
  5.   run S_HELLO on another. S_HELLO will send "hello world" messages,
  6.   this workstation will receive them.
  7.  
  8.   Polls the ECB until a packet is received. No ESR used.   }
  9.  
  10. uses crt,nwMisc,nwIPX;
  11.  
  12. CONST IOSocket=$5678;
  13.  
  14. Var ReceiveEcb:Tecb;
  15.     IpxHdr:TipxHeader;
  16.     socket:word;
  17.     buf:array[1..546] of byte;
  18.     t:byte;
  19.     w:word;
  20.     s:string;
  21.     ReceivedBufLen:word;
  22. begin
  23. IF NOT IpxInitialize
  24.  then begin
  25.       writeln('Ipx needs to be installed.');
  26.       halt(1);
  27.       end;
  28. socket:=IOSocket;
  29. IF NOT IPXopenSocket(Socket,SHORT_LIVED_SOCKET)
  30.  then begin
  31.       writeln('IPXopenSocket returned error# ',nwIPX.result);
  32.       halt(1);
  33.       end;
  34.  
  35. Repeat
  36.    { Empty receive buffer (ReceiveEcb.fragment[2].address^) }
  37.    FillChar(buf,546,#0);
  38.  
  39.    { Setup ECB and IPX header }
  40.    IPXsetupListenECB(NIL,IOsocket,@buf,546,
  41.                      IpxHdr,ReceiveEcb);
  42.    IPXListenForPacket(ReceiveECB);
  43.  
  44.    { Poll InUse flag until a packet was received }
  45.    while ReceiveECB.InUseFlag<>0
  46.     do IPXrelinquishControl;
  47.  
  48.    Case ReceiveECB.CompletionCode OF
  49.     $00:begin { Dump received bytes.. }
  50.         Write('Data received  : ');
  51.         ReceivedBufLen:=swap(IpxHdr.length)-SizeOf(TipxHeader);
  52.         for t:=1 to ReceivedBufLen
  53.          do write(chr(buf[t]));
  54.         writeln;
  55.         end;
  56.     $FC:Writeln('The listen request has been canceled.');
  57.         { impossible, as the cancelation has to be done by this program, and it doesn't }
  58.     $FD:Writeln('Packet overflow error.');
  59.         { 0 fragments, or receiving buffer too small. }
  60.     $FF:Writeln('The socket is closed.');
  61.         { Impossible. The socket is definitely open. See above. }
  62.    end;
  63.  
  64.    { Now we're going to squeeze all information out of the IpxHdr }
  65.    writeln('*IPX header info*');
  66.    writeln('-total length  : ',swap(IpxHdr.length):0);
  67.    writeln('-data length   : ',swap(IpxHdr.Length)-SizeOf(TipxHeader));
  68.    writeln('-number of hops: ',(IpxHdr.TransportControl AND $0F):0);
  69.    write('-sending adress: [');
  70.    for t:=1 to 4
  71.     do write(HexStr(IpxHdr.source.net[t],2));
  72.    write('|');
  73.    for t:=1 to 6
  74.     do write(HexStr(IpxHdr.source.node[t],2));
  75.    write('|');
  76.    writeln(HexStr(swap(IpxHdr.source.socket),4),']');
  77.    write('-destined for  : [');
  78.    for t:=1 to 4
  79.     do write(HexStr(IpxHdr.destination.net[t],2));
  80.    write('|');
  81.    for t:=1 to 6
  82.     do write(HexStr(IpxHdr.destination.node[t],2));
  83.    write('|');
  84.    writeln(HexStr(swap(IpxHdr.destination.socket),4),']');
  85.  
  86.    writeln;
  87. UNTIL keypressed;
  88.  
  89. IF NOT IPXcloseSocket(IOsocket)
  90.  then writeln('IPXcloseSocket returned error# ',nwIPX.result);
  91.  
  92. end.